import serial
import time

# 配置串口连接参数
ser = serial.Serial(
        port="/dev/ttyTHS1",
        baudrate=115200,
        bytesize=serial.EIGHTBITS,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        timeout=1
)

if ser.is_open == True:
    print("ok")

count = 0
recv = 0 
def rec_data():
    global recv
    global count
    count = ser.in_waiting
    if count != 0:
        recv = ser.read(ser.in_waiting)
        print(f"recv:{recv}")
    time.sleep(0.1)


while 1:
    rec_data()